%% Load the data - Select the File: 'TurningRate_QuasiSteady\Turning_Rates(33-66)'
close all; clear all; clc;
load('.\TurningRate_QuasiSteady\Turning_Rates(33-66).mat')
close all;
exps = {'control', '1cp', '2cp', '5cp', '9cp'};
Figure2c = figure('color',[1 1 1]); 
hold on; box on;
colors = {[0 0 0], [0.588 0.286 0.612], [0.929 0.694 0.125], [0.466 0.674 0.188], [0.85 0.325 0.0980]};
c = 0; Exp_X = []; Exp_Y = []; Exp_Error = []; Fit_X = []; Fit_Y = []; 
for i = [1,5]    
    Tau = mean_omega(i);
    if i == 1; Tau = -Tau; end
    x_bins = theta_bin_x{i}; Omega_Average = omega_bin{i}; Omega_error = omega_bin_std{i};
    x_fit = linspace(-pi, pi, 100); y_fit = -(Tau)*sin(x_fit);
    
    patch = fill([x_bins, fliplr(x_bins)], [30*(Omega_Average + Omega_error), 30*fliplr(Omega_Average - Omega_error)], colors{i});
    set(patch, 'edgecolor', 'none'); set(patch, 'FaceAlpha', 0.3);
    plot(x_fit, y_fit,'--','color',colors{i}, 'linew', 2)
    
    plot(x_bins, Omega_Average*30, '-','color',colors{i},'linew',2, 'MarkerFaceColor', colors{i})
    c = c + 1;
    Exp_X = x_bins; Exp_Y(:,c) = Omega_Average*30; Exp_Error(:,c) = Omega_error;
    Fit_X = x_fit; Fit_Y(:,c) = y_fit;
end
hold off;
xlim([-pi pi]); ylim([-12*10^(-2) 12*10^(-2)]); xlabel('Orientation \theta (rad)'); ylabel('Angular velocity \omega (s^-^1)');

xticks([-pi -pi/2 0 pi/2 pi]); yticks([-0.1 0 0.1]);

alw = 0.5; %Border line width
mypapersize = [2 2]; %[width height]
set(gca,'LineWidth',alw);
set(gca,'XColor',[0 0 0]);set(gca,'YColor',[0 0 0]);
set(gcf, 'PaperUnits', 'inches', 'papersize', mypapersize, 'PaperPosition', [0 0 mypapersize]);
xticklabels({'','','','',''});

yticklabels({'','','',''});
ylabel('');xlabel('');title('')
ax = gca;outerpos = ax.OuterPosition;ti = ax.TightInset;
left = outerpos(1);bottom = outerpos(2);ax_width = outerpos(3);ax_height = outerpos(4);
ax.Position = [left+0.035 bottom+0.01 ax_width-0.04 ax_height-0.02];

%Save Figure
dir = '.\Figure2';
print(Figure2c , '-painters','-dpdf', '-r1200', [dir,'\Fig2c.pdf']); %r1200

% Save Data
clc;
dir_excel = '.\Source data\MainText\';
tab = 3;
% Control
writematrix(Exp_X',[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','A4')
writematrix(Exp_Y(:,1),[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','B4')
writematrix(Exp_Error(:,1),[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','C4')
writematrix(Fit_X',[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','D4')
writematrix(Fit_Y(:,1),[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','E4')
% 9 cP
writematrix(Exp_X',[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','G4')
writematrix(Exp_Y(:,2),[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','H4')
writematrix(Exp_Error(:,2),[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','I4')
writematrix(Fit_X',[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','J4')
writematrix(Fit_Y(:,2),[dir_excel,'Figure2.xlsx'],'Sheet',tab,'Range','K4')